package com.jeesite.modules;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.utils.AES;
import com.jeesite.common.utils.Base64;
import com.jeesite.modules.ad.utils.api.utils.HttpUtil;

public class Test {
	private static final String KRY = "000000000000000wwwbeihancloudcom";

	private static final String PRO_URL = "http://wsq.beihancloud.com/ad/apiController/T1001";

	private static final String TEST_URL = "http://192.168.199.243:8980/js/apiController/T1001";

	public static void T1001() {
		// 调用接口,封装报文
		Map<String, Object> requestParams = new HashMap<String, Object>(16);
		// 请求参数
		requestParams.put("adVertisersAccount", "mkpkq");
		JSONObject jsonObject = new JSONObject(requestParams);
		String plainData = jsonObject.toString();
		System.out.println("请求报文:" + plainData);
		// 使用前十六位加密
		String encryptData = Base64.encode(AES.encode(plainData, KRY.substring(0, 16)));
		System.out.println(encryptData);
		// 使用后十六位签名
		String signData = DigestUtils.sha1Hex(plainData + KRY.substring(16));
		System.out.println(signData);
		Map<String, Object> params = new HashMap<String, Object>(2);
		params.put("encryptData", encryptData);
		params.put("signData", signData);
		// 调用接口
		String postResult = HttpUtil.post(TEST_URL, params);
		System.out.println(postResult);
	}

	public static void T1002() {
		// 调用接口,封装报文
		String url = "http://wsq.beihancloud.com/ad/apiController/T1002";
		Map<String, Object> requestParams = new HashMap<String, Object>(16);
		// 请求参数
		requestParams.put("phone", "17347029585");
		requestParams.put("phoneLocation", "中国湖南");
		requestParams.put("sex", "男");
		requestParams.put("age", "20");
		requestParams.put("career", "自由职");
		requestParams.put("guestTime", "2019-05-13 12:00:00");
		requestParams.put("media", "微信");
		requestParams.put("mediaUrl", "https://fanyi.baidu.com/translate");
		requestParams.put("advertisingPositionID", "123456");
		requestParams.put("landingPageURL", "https://fanyi.baidu.com/translate");
		requestParams.put("stayTime", "50");
		requestParams.put("message", "留言内容");
		requestParams.put("adVertiserId", "1128483234079154176");
		requestParams.put("advertisingProgrammeNameId", "1129321734490480640");

		JSONObject jsonObject = new JSONObject(requestParams);
		String plainData = jsonObject.toString();
		System.out.println("请求报文:" + plainData);
		// 使用前十六位加密
		String encryptData = Base64.encode(AES.encode(plainData, KRY.substring(0, 16)));
		// 使用后十六位签名
		String signData = DigestUtils.sha1Hex(plainData + KRY.substring(16));
		Map<String, Object> params = new HashMap<String, Object>(2);
		params.put("encryptData", encryptData);
		params.put("signData", signData);
		// 调用接口
		String postResult = HttpUtil.post(url, params);
		System.out.println(postResult);
	}

	public static void main(String[] args) {
		T1001();
	}
}
